//
//  TrainInfoDetailCtrl.m
//  laowu
//
//  Created by Northwan on 15/4/29.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "TrainInfoDetailCtrl.h"
#import "HomeDataTool.h"
#import "LWLoginCtrl.h"

@interface TrainInfoDetailCtrl ()
@property(nonatomic,strong)TrainInfoResult *result;
@end

@implementation TrainInfoDetailCtrl

+(instancetype)initWithTrainInfo:(TrainInfoResult*)result{
    TrainInfoDetailCtrl *object = [[TrainInfoDetailCtrl alloc]init];
    object.result = result;
    return object;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.scrollView setAlwaysBounceVertical:YES];
    [self initData];
}

-(void)initData{
    self.navigationItem.title = self.result.train_title;
    [_companyNameLabel setText:self.result.organization];
    [_trainPositionLabel setText:self.result.train_title];
    //培训费用 = 技能培训费+其他费用-国家补贴
    int fee = [self.result.train_skill_fee intValue] + [self.result.other_fee intValue] - [self.result.public_subsidies intValue];
    [_trainFreeLabel setText:[NSString stringWithFormat:@"%d元",fee]];
    [_referTelLabel setText:self.result.train_tel];
    [_techLevelLabel setText:self.result.train_skill_level];
    [_addressLabel setText:self.result.train_address];
    [_admissionsCountLabel setText:[NSString stringWithFormat:@"%@人",self.result.train_man_num]];
    [_trainAwayLabel setText:self.result.train_method];
    [_trainTimeLabel setText:self.result.train_during];
    [_techTrainCostLabel setText:[NSString stringWithFormat:@"%@元",self.result.train_skill_fee]];
    [_otherCostLabel setText:[NSString stringWithFormat:@"%@元",self.result.other_fee]];
    [_countrySubsidyLabel setText:[NSString stringWithFormat:@"%@元",self.result.public_subsidies]];
    [_gainTechLabel setText:self.result.skills_obtained];
}

- (IBAction)applyUp:(id)sender {
    
    if (!ISLOGIN) {
        LWLoginCtrl *ctrl = [[LWLoginCtrl alloc] init];
        [self presentViewController:[[CustomNavigationCtrl alloc] initWithRootViewController:ctrl] animated:YES completion:nil];
        return;
    }
    
    NSLog(@"我要报名");
    MBProgressHUD *lodingView =  [DialogUtils showLoadingWithView:self.view];
    [HomeDataTool applyTrainInfo:_result.id  success:^(BaseResponse *result) {
        [lodingView hide:YES];
        if(result.isSucc){
            [DialogUtils showTipsWithView:self.view String:@"报名成功"];
        }else{
            [DialogUtils showTipsWithView:self.view String:result.msg];
        }
    } failure:^(NSError *error) {
        [lodingView hide:YES];
        [DialogUtils showTipsWithView:self.view String:@"请求失败"];
    }];
}


@end
